package com.example;

/**
 * Student class demonstration program
 * Shows how to use the Student class and various Java features
 */
public class StudentDemo {
    public static void main(String[] args) {
        System.out.println("=== Java Student Management System Demo ===\n");

        // Create student objects - using different constructors
        Student student1 = new Student("2024001", "Zhang San", 20, "Computer Science");
        Student student2 = new Student("2024002", "Li Si", 19, "Software Engineering");
        Student student3 = new Student(Student.generateStudentId("Wang Wu", 2024), "Wang Wu");

        // Display student information
        student1.displayInfo();
        student2.displayInfo();
        student3.displayInfo();

        System.out.println("\n=== Adding Courses ===");

        // Add courses for students
        student1.addCourse("Java Programming");
        student1.addCourse("Data Structures");
        student1.addCourse("Algorithm Design");
        student1.addCourse("Database Systems");

        student2.addCourse("Python Programming");
        student2.addCourse("Web Development");

        // Display course lists
        student1.displayCourses();
        student2.displayCourses();

        // Test adding duplicate course
        student1.addCourse("Java Programming");

        System.out.println("\n=== Course Management ===");

        // Remove courses
        student2.removeCourse("Python Programming");
        student2.removeCourse("Non-existent Course");

        System.out.println("\n=== Age Management ===");

        // Test age setting
        System.out.println("Student3 current age: " + student3.getAge());
        student3.setAge(21);
        System.out.println("Student3 modified age: " + student3.getAge());

        // Test invalid age
        student3.setAge(-5);  // Invalid age
        student3.setAge(150); // Invalid age

        System.out.println("\n=== Object Comparison ===");

        // Create student with same ID
        Student student4 = new Student("2024001", "Zhang San Backup", 20, "Computer Science");

        // Test equals method
        System.out.println("student1 equals student4: " + student1.equals(student4));
        System.out.println("student1 equals student2: " + student1.equals(student2));

        System.out.println("\n=== toString Method ===");
        System.out.println(student1);
        System.out.println(student2);

        System.out.println("\n=== Complete Student List ===");
        Student[] students = {student1, student2, student3};

        // Use for loop
        for (int i = 0; i < students.length; i++) {
            System.out.println("Student " + (i + 1) + ": " + students[i].getName());
        }

        // Use enhanced for loop
        System.out.println("\nUsing enhanced for loop:");
        for (Student student : students) {
            student.displayCourses();
        }

        System.out.println("\n=== Demo Completed ===");
    }
}